package org.wd.db.jpa.dao.impls;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.wd.db.jpa.dao.ifs.StationDAOIf;
import org.wd.db.jpa.model.StationInfo;

public class StationDAOImpl implements StationDAOIf {

	@PersistenceContext(unitName = "RailGaadiPersistenceUnit")
	protected EntityManager entityManager;

	public void setEntityManager(EntityManager entityManager) {
		this.entityManager = entityManager;
	}

	public void saveStationInfo(StationInfo stationInfo) {
		entityManager.merge(stationInfo);
	}

	public StationInfo getStationInfoByStationCode(String stationCode) {
		return entityManager.find(StationInfo.class, stationCode);
	}

	@SuppressWarnings("unchecked")
	public List<StationInfo> getAllStationsInfo() {
		return (List<StationInfo>) entityManager.createQuery("SELECT si FROM StationInfo si order by si.code").getResultList();
	}
}
